﻿using System;
using System.Collections.Generic;
using System.Linq;
using TestModel;

namespace TestDBData.EFContext
{
    /// <summary>
    /// 基础仓储接口
    /// </summary>
    public partial interface IRepository<TEntity> where TEntity : BaseEntity
    {
        #region 方法
        /// <summary>
        /// 查询对象
        /// </summary>
        TEntity GetById(object gid);

        /// <summary>
        /// 添加
        /// </summary>
        void Insert(TEntity entity);

        /// <summary>
        /// 批量添加
        /// </summary>
        void Insert(IEnumerable<TEntity> entities);

        /// <summary>
        /// 修改
        /// </summary>
        void Update(TEntity entity);

        /// <summary>
        /// 批量修改
        /// </summary>
        void Update(IEnumerable<TEntity> entities);

        /// <summary>
        /// 删除
        /// </summary>
        void Delete(TEntity entity);

        /// <summary>
        /// 批量删除
        /// </summary>
        void Delete(IEnumerable<TEntity> entities);
        #endregion

        #region 查询数据集
        /// <summary>
        /// 查询数据集
        /// </summary>
        IQueryable<TEntity> Table { get; }

        /// <summary>
        /// 获取一个启用“no tracking”(EF特性)的表，仅当您仅为只读操作加载记录时才使用它
        /// </summary>
        IQueryable<TEntity> TableNoTracking { get; }
        #endregion

        /// <summary>
        /// 提交事务
        /// </summary>
        bool Commit(Action action);
    }
}
